package cn.wolfcode.consumer._8consumer_pull;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.List;

public class ConsumerTest {

    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {

        //创建一个拉取消息的消费者对象
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("wolfcode-consumer");
        //设置名字地址
        consumer.setNamesrvAddr("127.0.0.1:9876");
        //启动消费者
        consumer.start();
        //拉取消息
        PullResult pullResult = consumer.
                pull(new MessageQueue("8_pull", "broker-a", 3), "*", 0, 1);

        for (MessageExt messageExt : pullResult.getMsgFoundList()) {
            System.out.println("消费线程:"+Thread.currentThread().getName()+",消息ID:"+messageExt.getMsgId()+",消息内容:"+new String(messageExt.getBody()));
        }
        consumer.shutdown();
    }
}
